package bussines.progress;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @copyright (C) 2008 - Andrei Musca
 * @author andreimusca
 * @created : Oct 26, 2008
 * 
 **/
public class ProgressManager {

	private List<ProgressListener> progressListeners = new ArrayList<ProgressListener>();

	private static ProgressManager instance = null;

	private ProgressManager() {

	}

	public void addProgressListener(ProgressListener pl) {
		progressListeners.add(pl);
	}

	public void removeProgressListener(ProgressListener pl) {
		progressListeners.remove(pl);
	}

	public void notifyProgressListenersOnStart(int max) {
		for (ProgressListener pl : progressListeners) {
			pl.onStart(max);
		}
	}

	public void notifyProgressListenersOnProgress(int step) {
		for (ProgressListener pl : progressListeners) {
			pl.onProgress(step);
		}
	}

	public static synchronized ProgressManager getInstance() {
		if (instance == null) {
			instance = new ProgressManager();
		}
		return instance;
	}
}
